
module libeventd.event.Internal ;

import
	libeventd.Types ;

enum{
	EV_CLOSURE_NONE	= 0 ,
	EV_CLOSURE_SIGNAL	= 1 ,
	EV_CLOSURE_PERSIST	= 2 ,
}

extern(C):

struct eventop {
	char*	name;
	void* function(event_base*)	init;
	ev_int function(event_base*, evutil_socket_t, ev_short, ev_short, void *) 	add;
	ev_int function(event_base*, evutil_socket_t, ev_short, ev_short , void *)	del;
	ev_int function(event_base *, timeval *)	dispatch;
	void function(event_base*)	dealloc;
	ev_int	need_reinit;
	event_method_feature	features;
	size_t	fdinfo_len;
}

struct event_signal_map {
	void**	entries;
	int		nentries;
}

struct common_timeout_list {
	TAILQ_ENTRY!(event)	events;
	timeval			duration;
	event			timeout_event;
	event_base*		base;
}

struct event_changelist {
	event_change*	changes;
	ev_int		n_changes;
	ev_int		changes_size;
}

struct event_base {
	eventop*				evsel;
	void*				evbase;
	event_changelist			changelist;
	eventop*				evsigsel;
	evsig_info				sig;
	ev_int				virtual_event_count ;
	ev_int				event_count;
	ev_int				event_count_active;
	ev_int				event_gotterm;
	ev_int				event_break;
	ev_int				running_loop;
	event_list*				activequeues;
	ev_int				nactivequeues;
	common_timeout_list**		common_timeout_queues;
	ev_int				n_common_timeouts;
	ev_int				n_common_timeouts_allocated;
	deferred_cb_queue		defer_queue;
	event_io_map			io; 
	event_signal_map		sigmap;
	event_list				eventqueue;
	timeval				event_tv;
	min_heap				timeheap;
	timeval				tv_cache;

version(_EVENT_DISABLE_THREAD_SUPPORT) {}else{
	ev_ulong				th_owner_id;
	void*				th_base_lock;
	event*				current_event;
	void*				current_event_cond ;
	ev_int				current_event_waiters ;
}

version(Windows){
	event_iocp_port*			iocp;
}

	event_base_config_flag		flags;
	ev_int				is_notify_pending;
	ev_int[2]				th_notify_fd;
	event				th_notify;
	ev_int function(event_base *base)	th_notify_fn;
}

struct event_config_entry {
	TAILQ_ENTRY!(event_config_entry)	next;
	char*	avoid_method;
}
struct event_configq{
	mixin TAILQ_HEAD!(event_config_entry);
}

struct event_config {
	event_configq	entries;
	ev_int		n_cpus_hint;
	event_method_feature	require_features;
	event_base_config_flag	flags;
}

